<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>事件冒泡</title>
    <style>
      #a,
      #b,
      #c {
        display: flex;
        justify-content: center;
        align-items: center;

        border: 1px solid gray;
      }
      #a {
        width: 200px;
        height: 200px;
        background-color: lightblue;
      }
      #b {
        width: 80%;
        height: 80%;
        background-color: lightgreen;
      }
      #c {
        width: 80%;
        height: 80%;
        background-color: orangered;
      }
    </style>
  </head>
  <body>
    <div id="a">
      1
      <div id="b">
        2
        <div id="c">3</div>
      </div>
    </div>
    <script>
      document.getElementById('a').addEventListener(
        'click',
        function () {
          alert(1)
        },
        false
      )
      document.getElementById('b').addEventListener(
        'click',
        function () {
          alert(2)
        },
        false
      )
      document.getElementById('c').addEventListener(
        'click',
        function (e) {
          e.stopPropagation()
          alert(3)
        },
        false
      )
    </script>
  </body>
</html>
